<?php
namespace app\common\model;

class OrderModel extends BaseModel
{
	protected $name = 'order';

	const PAY_DOU = 1;
	const PAY_DOU_2 = 2;
	const PAY_WEIXIN = 3;
	const PAY_NOT = 4;
	const PAY_NEW_CARD = 5;
	const PAY_CARD = 6;
	const PAY_MERGE_CARD = 7;
	const PAY_ALIPAY = 8;
	const PAY_MERGE_ALIPAY = 9;
	const PAY_MERGE = 10;
	const PAY_MERGE_DOU = 11;
	public static $pay_mode_list = [
		self::PAY_DOU => 'DOU分期',
		self::PAY_DOU_2 => '抖音零钱',
		self::PAY_WEIXIN => '微信',
		self::PAY_NOT => '无需支付',
		self::PAY_NEW_CARD => '新卡支付',
		self::PAY_CARD => '银行卡',
		self::PAY_MERGE_CARD => '银行卡支付-定金;银行卡支付-尾款',
		self::PAY_ALIPAY => '支付宝',
		self::PAY_MERGE_ALIPAY => '支付宝支付-定金;支付宝支付-尾款',
		self::PAY_MERGE => '组合支付',
		self::PAY_MERGE_DOU => '组合支付支付-定金;DOU分期-尾款',
	];

	const STATUS_SUBMIT = 10;
	const STATUS_PAY = 20;
	const STATUS_POST = 30;
	const STATUS_FINISH = 40;
	public static $status_list = [
		self::STATUS_SUBMIT => '已提交',
		self::STATUS_PAY => '已支付',
		self::STATUS_POST => '已发货',
		self::STATUS_FINISH => '已完成',
	];
	
	/**
	 * 查询
	 * @Author   zhibin3
	 * @DateTime 2022-10-19
	 * @param    string     $value [description]
	 * @return   [type]            [description]
	 */
	public static function get_pay_mode($value='')
	{
		if (empty($value)) return 0;
		$pay_mode_list = self::$pay_mode_list;
		$key = array_search('DOU分期', $pay_mode_list);
		return $key;
	}

	public static function get_status($value='')
	{
		if (empty($value)) return 0;
		$status_list = self::$status_list;
		$key = array_search($value, $status_list);

		return $key;
	}

	/**
	 * 查询列表
	 * @Author   zhibin
	 * @DateTime 2019-11-18
	 * @param    array      $where     [description]
	 * @param    integer    $nowPage   [description]
	 * @param    integer    $limits    [description]
	 * @return   [type]                [description]
	 */
	public function getPageList(array $where=[], $page=1, $limit=10, $field='*', $order='o.id desc')
	{
		$pageList = $this->alias('o')
				->join('tk_product p', 'p.product_code=o.product_code', 'left')
				->where($where)->field($field)
				->order($order)->paginate($limit);
		// echo $this->getLastSql();die;
		$page = $pageList->render();
		$pageList = json_decode(json_encode($pageList), true);
		$pageList['page'] = $page;

		return $pageList;
	}

}